﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using MVVM_CAD.Algorithms;
using MVVM_CAD.Common;
using MVVM_CAD.Model;
using Ninject;
using System.Windows.Controls;

namespace MVVM_CAD.Strategy
{
    public abstract class StrategyBase : IStrategy
    {
        #region Atributtes
        protected int ClickCount;
        protected IKernel Kernel;
        public IFigure Figure { get; set; }

        #endregion

        #region Behaviors

        public abstract IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures);
        public abstract IFigure PerformMouseLeftClicUpEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures);
        public abstract IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures);
        public abstract IFigure PerformMouseMoveEvent(IPoint point, IEnumerable<IFigure> figures);
        public abstract IFigure PerformMouseMoveEvent(DrawingCanvas Canvas, CustomPoint point);
        
        #endregion

        #region Constructor
        protected StrategyBase(IFigure figure)
        {
            Figure = figure;
            Kernel = new StandardKernel(new MainViewModelModule());
        }
        #endregion

        #region Methods
        protected void DrawFigureInCanvas(Canvas canvas, IEnumerable<IPoint> figureRepresentation)
        {
            AddPointsToCollection(figureRepresentation);

            FigureDrawer.DrawFigure(canvas, Figure);
        }

        protected IFigure CloseFigureDrawing()
        {
            Figure.DrawStatus = DrawStatus.Completed;
            ClickCount = 0;

            return Figure;
        }

        protected void ValidateFigureIsNew<T>() where T : IFigure
        {
            if (Figure.PointsCollection.Count != 0) Figure = Kernel.Get<T>();
        }

        public void AddPointsToCollection(IEnumerable<IPoint> figureRepresentation)
        {
            foreach (var pointInLine in figureRepresentation)
                Figure.PointsCollection.Add(pointInLine);
        }

        protected static void AddNewObject(DrawingCanvas drawingCanvas, FigureBase o)
        {
            //HelperFunctions.UnselectAll(drawingCanvas);

            o.IsSelected = true;
            o.Clip = new RectangleGeometry(new Rect(0, 0, drawingCanvas.ActualWidth, drawingCanvas.ActualHeight));

            drawingCanvas.VisualCollection.Add(o);
            drawingCanvas.CaptureMouse();
        }


        #endregion

    }
}
